#ifndef __KERNEL__
#define __KERNEL__


#include <tchar.h>
#include <atomic> 
#include <unordered_map>
#include "IKernel.h"
#include "IObject.h"
#include "FrameTools.h"



class CKernel : public virtual IKernel
{
public:
	~CKernel();
	const bool Init( const void * pvdPara, char * pszMsgTxt, int iMsgTxtSize )override final;
	void AddInstance( void * ptrInstance )override final;
	void * Invoke(const char * pszClassName, const void * pvdParaVal, char * pszMsgTxt, const int iMsgTxtSize, int &iInstanceType, const bool bCreateValSetFlg = true)override final;
	void * CreateValueSet();
	const void WriteLog( const char * pszLogTxt, const int iWriteLevel, const char * pszVersion = "")override final;
	const bool StopFlg()override final;
	const void Stop();
    const void DisableDataConnect();
	const bool InitFlg();
	const char * ConfigFileName();
	const char * LastErrMsg();
	static void * Instance(void);
	const bool WriteFlg();
	const int WriteLevel();
	const int UnRegHeartbeat(long long llProID);
    const void RegHeartbeat(long long llProID);
    const bool IsCorpse(long long llProID);
	const int GetConnectTimeOut();	
	void * Tools();
private:
	shared_ptr< unordered_map< string, shared_ptr< IBaseObject > > > m_ptrMpInstance;
    ILock * m_LockHeartbeat;


	shared_ptr<IFrameTools> m_ptrFrameTools;
    map<long long, long long> m_mpHeartbeat;
	map< string, HMODULE > m_MpDllHnd;
	atomic<bool> m_bExitFlg;	
	int m_iInstanceType, m_iWriteLevel, m_iDsOutTime, m_iConnectTimeOut;
	bool m_bInitFlg, m_bWriteFlg;
	string m_strConfigFileName, m_strLastErrMsg, m_strLogPath, m_strMntLbmNo;
	::HANDLE m_hProcess;
private:	
	bool LoadConfigFile(char * pszConFileName, CFrameTools * ptrFrameTools);
	bool FileExists( char * szFileName );
	bool StrEmpty( char * szStr );
	int StrCount(char * pszStr, char * pszSpeStr);
	int Pos(char * pszStr, char * pszSubStr);
	char * CurrentPath(char *pszPath, int iLen);
    const int Type();
	::DWORD m_dwErrCode;

};

#endif//__KERNEL__
